package com.wty.basic.reflect;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * 通过反射越过泛型检查
 * @Author wangtengyu
 * @Create 2018-08-09-10:59
 */
public class Generic {


    @Test
    public void test() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        List<String> strList=new ArrayList<>();
        strList.add("wty");
        strList.add("kids");
//        strList.add(100);//报错

        Class clazz=strList.getClass();
        Method addMethod=clazz.getDeclaredMethod("add",Object.class);
        addMethod.invoke(strList,100);

        for (Object o:strList){
            System.out.println(o);
        }

    }
}
